ForEach(TSource) Method (OrderablePartitioner(TSource), Action(TSource, ParallelLoopState, Int64))

Task Parallel System.Threading

Executes a for each operation on a OrderablePartitioner in which iterations may run in parallel.

Namespace:  System.Threading.Tasks
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function ForEach(Of TSource) ( _
	source As OrderablePartitioner(Of TSource), _
	body As Action(Of TSource, ParallelLoopState, Long) _
) As ParallelLoopResult
C#
public static ParallelLoopResult ForEach<TSource>(
	OrderablePartitioner<TSource> source,
	Action<TSource, ParallelLoopState, long> body
)

Parameters

source
Type: System.Collections.Concurrent..::.OrderablePartitioner<(Of <(TSource>)>)
The OrderablePartitioner that contains the original data source.
body
Type: System..::.Action<(Of <(TSource, ParallelLoopState, Int64>)>)
The delegate that is invoked once per iteration.

Type Parameters

TSource
The type of the elements in source.

Return Value

A ParallelLoopResult structure that contains information on what portion of the loop completed.

Remarks

The Partitioner is used to retrieve the elements to be processed, in place of the original data source. If the current element's index is desired, the source must be an OrderablePartitioner.

The body delegate is invoked once for each element in the source Partitioner. It is provided with the following parameters: the current element, a ParallelLoopState instance that may be used to break out of the loop prematurely, and the current element's index (an Int64).

Exceptions

ExceptionCondition
System..::.ArgumentNullExceptionThe exception that is thrown when the source argument is null.
System..::.ArgumentNullExceptionThe exception that is thrown when the body argument is null.
System..::.InvalidOperationExceptionThe exception that is thrown when the SupportsDynamicPartitions property in the source OrderablePartitioner returns false.
System..::.InvalidOperationExceptionThe exception that is thrown when the KeysNormalized property in the source OrderablePartitioner returns false.
System..::.InvalidOperationExceptionThe exception that is thrown when any methods in the source OrderablePartitioner return null.
System..::.InvalidOperationExceptionThe exception that is thrown when the GetPartitions() or GetOrderablePartitions() methods in the source OrderablePartitioner do not return the correct number of partitions.
System..::.InvalidOperationExceptionThe exception that is thrown when the GetPartitions() or GetOrderablePartitions() methods in the source OrderablePartitioner return an IList with at least one null value.
System..::.InvalidOperationExceptionThe exception that is thrown when the GetDynamicPartitions() or GetDynamicOrderablePartitions() methods in the source OrderablePartitioner return an IEnumerable whose GetEnumerator() method returns null.
System..::.AggregateExceptionThe exception that is thrown to contain an exception thrown from one of the specified delegates.

See Also